import React from 'react'
import { Modal, Input, message } from 'antd'
import { hide } from '../../redux/actionCreator/TabbarActionCreator'
import { connect } from 'react-redux'
import { changeSaveCommit, saveTemp, changeTempList, changeTempOption } from '../../redux/actionCreator/lineLossTempActionCreater'
import moment from 'moment'

const { TextArea } = Input
// 对话框
function SaveBox (props) {

  let { isShow, hide, viewId, changeSaveCommit, saveCommit, saveTemp, changeTempList } = props

  return (
    <div>
      <Modal
        title="保存"
        visible={isShow}
        okText="保存"
        cancelText="取消"
        onOk={() => {
          if (saveCommit === "") {
            return message.error("请输入备注！")
          } else {

            let saveOption = window.luckysheet.getAllSheets()

            //日期
            let date = moment().format('YYYY-MM-DD HH:mm:ss')
            // 保存,并修改了更新时间
            saveTemp(viewId, saveCommit, saveOption, date)
            // 将redux中的list变为空数组，通知list模态框刷新
            changeTempList([])



            //关闭窗口
            hide()
          }
        }}
        onCancel={hide}>
        <div>
          <span>请输入备注</span>
          <TextArea showCount maxLength={200} style={{ height: 120 }} onChange={(e) => {
            //将输入框数据传给公共状态
            changeSaveCommit(e.target.value)
          }} />
        </div>
      </Modal>
    </div>
  )
}

const mapStateToProps = (state) => {
  return {
    viewId: state.LineLossTempReducer.viewId,
    isShow: state.TabbarReducer.visible,
    saveCommit: state.LineLossTempReducer.saveCommit,
  }
}

const mapDispatchToProps = {
  hide,
  changeSaveCommit,
  saveTemp,
  changeTempList,
  changeTempOption
}

export default connect(mapStateToProps, mapDispatchToProps)(SaveBox)